<?php
namespace app\common\model;
use think\facade\Request;
use think\facade\Cache;
use think\db;
/**
 * 商品模型
 * Class Item
 * @package app\common\model
 */
class MerchantMoney extends BaseModel
{


    public function getContentAttr($value)
    {
        return htmlspecialchars_decode($value);
    }


    /**
     * 获取详情
     */
    public static function detailad($merchant_id)
    {

        if($merchant_id){
            $money1 = DB::table('bfb_merchant_money')
                ->where('merchant_id', '=', $merchant_id)
                ->where('code','=','1')
                ->sum('shop_money');
            $money2 = DB::table('bfb_merchant_money')
                ->where('merchant_id', '=', $merchant_id)
                ->where('code','=','2')
                ->sum('shop_money');
            $money = $money1 - $money2;
            if($money >0){
                return $money;
            }
        }
        return false;

    }

    /**
     * 列表
     */
    public static function listsad($merchant_id)
    {
        if($merchant_id){
            $money1 = DB::table('bfb_merchant_money')
                ->where('merchant_id', '=', $merchant_id)
                ->field(['order_no','shop_money','code','create_time'])
                ->order('create_time desc')
                ->select();
            return $money1;
        }
            return false;
    }

    /**
     * 获取图片
     */
    public static function detailimg($goods_id)
    {
        if($goods_id){
            return DB::table('bfb_item_images')
                ->where('item_id', '=', $goods_id)
                ->field('image_id')
                ->select();

        }
    }

    /**
     * 商品上下架
     */
    public static function updatestate($goods_id,$state = '1')
    {
        if($goods_id){
            return DB::table('bfb_item')
                ->where('goods_id', '=', $goods_id)
                ->update(['is_on_sale' => $state,'update_time'=>time()]);

        }
    }
}